/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cadastro.struts;

import DAO.cadastro.CadastroPaciente;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author tademir001
 */
public class CadastrarPacienteAction extends org.apache.struts.action.Action {

    /*
     * forward name="success" path=""
     */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        CadastroPaciente inseriu = new CadastroPaciente();

        int idconvenio  = Integer.parseInt(request.getParameter("idconvenio"));
        int matricula   = Integer.parseInt(request.getParameter("matricula"));
        String nome     = request.getParameter("nome");
        String nomemae  = request.getParameter("nomemae");
        String endereco = request.getParameter("endereco");
        String cep      = request.getParameter("cep");
        String bairro   = request.getParameter("bairro");
        String cidade   = request.getParameter("cidade");
        String uf       = request.getParameter("uf");
        String titular  = request.getParameter("titular");
        int rg          = Integer.parseInt(request.getParameter("rg"));
        int cpf         = Integer.parseInt(request.getParameter("cpf").replace("-", "").replace(".",""));
        String nomepai  = request.getParameter("nomepai");
        String obs      = request.getParameter("obs");
        
        Boolean resultado = inseriu.inserirPaciente( matricula, idconvenio, nome, 
                                                     nomemae,  endereco,  cep, 
                                                     bairro,  cidade,  uf, titular,
                                                     rg, cpf, nomepai, obs);

        if (resultado.equals(true)) {
            response.getWriter().write("{success:true}");
        } 
        return null;
    }
}
